import java.io.IOException;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.sql.Time;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;


public class LigneBus extends TimerTask{
	private HashMap<Integer, Bus> lb;
	private String nom;
	private int num;
	private UDP c;
	
	public LigneBus(int num,int nb) throws IOException{
		lb = new HashMap<Integer, Bus>();
		nom = "ligne"+num;
		this.num = num;
		c = new UDP("localhost",4000, 1024);
		//c.envoie(Integer.toString(this.num));
	}
	
	public void addBus(Bus b){
		lb.put(b.getNum(), b);
	}

	/*
	public String toString(){
		String r ="Ligne numero:"+num+"\n";
		for (int i = 0; i < lb.size(); i++) {
			r += lb.get(i).toString()+"\n";
		}
		return r;
	}*/
	
	public void run(){
		try { 
			
			for (Bus b : lb.values()) {
				System.out.println(b.toString());
				c.envoie(b.toString());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	public static void main (String[] args) throws IOException{
		int num = 1;
		int taille = 5;
		LigneBus maLigne = new LigneBus(num,taille); 
		maLigne.addBus(new Bus(11, "St. Paul", "La Defense",30,"normal"));
		maLigne.addBus(new Bus(24, "Argentine", "Chateau De Vincennes",30,"normal"));
		maLigne.addBus(new Bus(6, "Montparnasse", "Nation",40,"normal"));
		maLigne.addBus(new Bus(8, "Opera", "Creteil",30,"normal"));
		maLigne.addBus(new Bus(10, "Jussieu", "Gare d'Austerliz",40,"normal"));
		maLigne.c.envoie(Integer.toString(num));
		Timer timer = new Timer();
		timer.schedule(maLigne,0,15000);
		ReceptionOrdre r = new ReceptionOrdre(maLigne.lb);
		r.start();
	}
	
}
